//
//  HWVoiceRoomGiftCell.swift
//  PlayWithProject
//
//  Created by 王昌健 on 2021/8/27.
//

import UIKit

class HWVoiceRoomGiftCell: UICollectionViewCell {
    var imageView:UIImageView!
    var giftName:UILabel!
    var priceLabel:UILabel!
    var priceImage:UIImageView!
    var priceView:UIView!
    var selectBorderView:UIImageView!
    
    var model:HWVoiceRoomGiftModel? {
        didSet {
            imageView.sd_setImage(with: URL(string: model?.icon ?? ""), completed: nil)
            giftName.text = model?.name
            priceLabel.text = model?.money
            if model?.selected == true {
                selectBorderView.isHidden = false
            }else{
                selectBorderView.isHidden = true
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
extension HWVoiceRoomGiftCell {
    private func initUI() -> Void {
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        imageView = UIImageView()
        imageView.backgroundColor = .clear
        contentView.addSubview(imageView)
        
        priceView = UIView()
        contentView.addSubview(priceView)
        
        giftName = HWLabel.createLabel(title: "3", color: "#FFFFFF", font: 12)
        priceView.addSubview(giftName)
        
        priceLabel = HWLabel.createLabel(title: "1", color: "#FFFFFF", font: 8)
        priceView.addSubview(priceLabel)
        
        priceImage = UIImageView()
        priceImage.image = UIImage(named: "diamonds_Small")
        priceView.addSubview(priceImage)
        
        selectBorderView = UIImageView()
        selectBorderView.image = UIImage(named: "giftSelectBorder")
        contentView.addSubview(selectBorderView)
        selectBorderView.isHidden = true
        
    }
    
    private func initFrame() -> Void {
        imageView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(5)
            make.width.height.equalTo(56)
        }
        
        giftName.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(imageView.snp.bottom).offset(2)
        }
        
        priceView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(giftName.snp.bottom).offset(2)
        }
        
        priceLabel.snp.makeConstraints { make in
            make.left.top.bottom.equalTo(0)
        }
        
        priceImage.snp.makeConstraints { make in
            make.width.height.equalTo(8)
            make.left.equalTo(priceLabel.snp.right).offset(5)
            make.right.equalTo(0)
            make.centerY.equalTo(priceLabel)
        }
        
        selectBorderView.snp.makeConstraints { make in
            make.left.top.right.bottom.equalTo(0)
        }
    }
}
